﻿using AutoMapper;
using MediatR;
using MyMES.Domain.W.Liststructure;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Writer.API.Application.Commends.W.realize;

namespace MyMES.Writer.API.Application.CommendHandlers.W.realize
{
    public class UpdateMaterialproductclassificationCommandHanders : IRequestHandler<UpdateMaterialproductclassificationCommands, APIResult<Materialproductclassification>>
    {
        private readonly IBaseRepository<Materialproductclassification> _repository;
        private readonly IMapper mapper;

        public UpdateMaterialproductclassificationCommandHanders(IBaseRepository<Materialproductclassification> repository, IMapper mapper)
        {
            _repository = repository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 修改物料产品信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<Materialproductclassification>> Handle(UpdateMaterialproductclassificationCommands request, CancellationToken cancellationToken)
        {
            APIResult<Materialproductclassification> result = new APIResult<Materialproductclassification>();
            result.Code = APIEnum.修改成功;
            result.Msg = "修改成功";
            var maps= mapper.Map<Materialproductclassification>(request);
            var list = "Update Materialproductclassification set Classificationname=@Classificationname,Sort=@Sort,Materialproduct=@Materialproduct,IsEnable=@IsEnable,STime=@STime,IsDelete=@IsDelete where ParentId=@ParentId";
            await _repository.Update(maps, list);
            return result;
        }
    }
}
